﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;
using SelfService.Model;


namespace SelfService.ViewModel.SysOperatorVMs
{
    public partial class SysOperatorListVM : BasePagedListVM<SysOperator_View, SysOperatorSearcher>
    {

        protected override IEnumerable<IGridColumn<SysOperator_View>> InitGridHeader()
        {
            return new List<GridColumn<SysOperator_View>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.ClientName),
                this.MakeGridHeader(x => x.Password),
                this.MakeGridHeader(x => x.Token),
                this.MakeGridHeader(x => x.IsEnable),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysOperator_View> GetSearchQuery()
        {
            var query = DC.Set<SysOperator>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.GroupId, x=>x.GroupId)
                .CheckEqual(Searcher.ClientId, x=>x.ClientId)
                .CheckEqual(Searcher.IsEnable, x=>x.IsEnable)
                .Select(x => new SysOperator_View
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    Description = x.Description,
                    GroupName = x.Group.Name,
                    ClientName = x.Client.Name,
                    Password = x.Password,
                    Token = x.Token,
                    IsEnable = x.IsEnable,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysOperator_View : SysOperator{
        [Display(Name = "分类")]
        public string GroupName { get; set; }
        [Display(Name = "客户端")]
        public string ClientName { get; set; }

    }
}
